// CORE.h
////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef __CORE_H__
#define __CORE_H__

#include "../Core/AssertEx.h"

////////////////////////////////////////////////////////////////////////////////////////////////////

#define USE_THREAD_FOR_GAME		(1)
#define USE_ACCELEROMETER		(0)
#define USE_TIME_PROFILE		(0)

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#define TWEAK_CAMERA	0

////////////////////////////////////////////////////////////////////////////////////////////////////
//RedStorm's Reminder: usage: #pragma REMINDER("type your message")
//Will show up at compile time and will allow go-to-line with double-click.

#ifdef _DEBUG
  #define REMINDER_STR(x)	#x
  #define REMINDER(msg)		message(__FILE__ "(" REMINDER_STR(__LINE__) ") : " msg)
  #define HARDCODED(v)		message(__FILE__ "(" REMINDER_STR(__LINE__) ") : warning: '"#v"' : value is hardcoded")	
#else
  #define REMINDER_STR(x)
  #define REMINDER(msg)
  #define HARDCODED(v)
#endif

#define NEW							new 
#define SAFE_DEL(a)					{if(a){delete (a);a=NULL;}}
#define SAFE_DEL_ARRAY(a)			{if(a){delete[] (a);a=NULL;}}
#define SAFE_DEL_ARRAY_TYPE(a,t)	{if((t)a){delete[] ((t)a);a=NULL;}}
#define SAFE_DEL_ARRAY_OBJ(p, n)	{ if (p) { for (int __i = 0; __i < n; __i++) SAFE_DEL((p)[__i]); delete[] (p); p = NULL; } }
#define SAFE_DROP(a)				{if(a){(a)->drop();a=NULL;}}

typedef float				TimeStamp;
typedef unsigned long long	StreamSize;
typedef short				Coord;

#if WIN32
	typedef wchar_t				GX_CHAR;
#else
	typedef unsigned short		GX_CHAR;
#endif

#ifndef pure
#define pure =0
#endif

#ifndef NULL
#define NULL 0
#endif

////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

#if !defined(MIN)
	#define MIN(x,y)		((x)<(y)?(x):(y))
#endif 
#if !defined(MAX)
	#define MAX(x,y)		((x)>(y)?(x):(y))
#endif
#if !defined(ABS)
	#define ABS(x)			((x)<0?-(x):(x))
#endif
#if !defined(SGN)
	#define SGN(x)			((x)<0?-(1):(1))
#endif
#if !defined(SQR)
	#define SQR(x)			((x)*(x))
#endif

// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Platform specifics
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#if WIN32
	//#define MEMORY_DEBUG
	#define MAX_PTR							(8192)

	#ifdef _DEBUG

		#define DEBUG_OUT					debug_out
		#define DEBUG_OUT_VECTOR(v)			debug_out("VEC: %s = %f, %f, %f\n", #v, v.X, v.Y, v.Z)
		#define DEBUG_OUT_VECTOR3(v)		debug_out("VEC: %s = %f, %f, %f\n", #v, v.x, v.y, v.z)
		#define FAIL(x , s)								if (!x) {debug_out("//---------------------\n//FAIL %s - %s \n//---------------------\n", #x , s);}
	#else
		#define DEBUG_OUT
		#define DEBUG_OUT_VECTOR(v)
		#define DEBUG_OUT_VECTOR3(v)
		#define FAIL(x , s)
	#endif	

#endif

#if defined(TARGET_IPHONE_SIMULATOR) || defined(TARGET_OS_IPHONE)
	#ifdef _DEBUG
		#define DEBUG_OUT		printf
		#define DEBUG_OUT_VECTOR(v)
		#define DEBUG_OUT_VECTOR3(v)
	#else
		#define DEBUG_OUT
		#define DEBUG_OUT_VECTOR(v)
		#define DEBUG_OUT_VECTOR3(v)
	#endif 
	#define FAIL(x , s)	
#endif

#include "../Common/logger.h"

#define GAME_APP_PATH			"/Spiderman.app/"
#define GAME_APP_VER			"v.0.0.1"

extern "C" int S_GetTime(void);
extern "C" int S_GetTimeMicros(void);

#if USE_TIME_PROFILE

extern "C" long t_draw;
extern "C" long t_update;

extern "C" long t_d_update;
extern "C" long t_d_draw;
extern "C" long t_d_draw2;

extern "C" long t_d_register;
extern "C" long t_d_skybox;
extern "C" long t_d_sort;
extern "C" long t_d_solid;
extern "C" long t_d_trans;
extern "C" long t_d_flush;

#endif //USE_TIME_PROFILE


#define SEC_TO_MS(a)	(a*1000)
#define MS_TO_SEC(a)	(a*0.001f)


#endif //__CORE_H__
